$(function () {
    $('#menubtn').click(function(){
      $("#navBar").css({
        backgroundColor:"white",
      })
    })
  })
  

var test = 9
function getCookie(token){
  var token = token + "=";
  var ca = document.cookie.split(';');
  for(var i=0; i<ca.length; i++) {
    var c = ca[i].trim();
    if (c.indexOf(name)==0) { return c.substring(token.length+4,c.length); }
  }
  return "";
}
var token = window.sessionStorage.token;
// var token1 = window.sessionStorage.token.substring(3,window.sessionStorage.token.length);
// var token = getCookie("token")
var phone = window.location.search
var url = host + '/userdetail'+ phone +'&token=' + token 
let httpRequest = new XMLHttpRequest();//第一步：创建需要的对象
// {#httpRequest.open('POST', 'url', true); //第二步：打开连接/***发送json格式文件必须设置请求头 ；如下 - */#}
httpRequest.open('GET', url, true); //第二步：打开连接/***发送json格式文件必须设置请求头 ；如下 - */
httpRequest.setRequestHeader("Authorization", token);
// httpRequest.setRequestHeader("token", localStorage.token);
httpRequest.setRequestHeader("Access-Control-Allow-Credentials", true);//设置请求头 注：post方式必须设置请求头（在建立连接后设置请求头）var obj = { name: 'zhansgan', age: 18 };
httpRequest.setRequestHeader("Access-Control-Allow-Origin", "*");
// httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
httpRequest.send();//发送请求 将json写入send中
/**
 * 获取数据后的处理程序
 */
httpRequest.onreadystatechange = function () {//请求后的回调接口，可将请求成功后要执行的程序写在其中
    if (httpRequest.readyState == 4 && httpRequest.status == 200) {//验证请求是否发送成功
        var json = JSON.parse(httpRequest.responseText);//获取到服务端返回的数据
        console.log(json);

        var username = json['username']
        $('#username').html('<p style="font-size: 18px;">姓名：'+ username + '</p>')

        var Branch = {
          0:'招商部',
          1:'运营部',
          2:'媒介部',
          3:'行政部',
          4:'财务部',
          5:'直播部',
          6:'技术部',
        }
        var branch = json['branch']
        test = branch
        $("#serach").click(function(){
          window.location.href = './administration.html?test=' + test
        })
        
        $("#" + test).children().children().each(function(){
            $(this).attr('disabled',false);
        })  
        $("#" + test).parent().siblings().children('.dropdown-toggle').each(function(){
            console.log(123);
            $(this).click(function(){
                alert('无部门权限！')
            })
        })
        for(var i in Branch){
            if( branch==i ){
              $('#branch').html('<p style="font-size: 18px;">部门：' + Branch[i] + '</p>')
            }
        }
        
        var gender = json['gender']
        if(gender == 'male'){
          $('#gender').html('<p style="font-size: 18px;">性别：男</p>')
          $('#image').html('<img src="./images/gender0.png" class="img-circle" style="width: 80px;border: 2px  solid black;margin: 20px;">')
        }else if(gender == 'female'){
          $('#gender').html('<p style="font-size: 18px;">性别：女</p>')
          $('#image').html('<img src="./images/gender1.png" class="img-circle" style="width: 80px;border: 2px  solid black;margin: 20px;">')
        }
    }
};
